package com.zbkj.admin.controller;

import com.zbkj.admin.service.AdminClientUserService;
import com.zbkj.common.model.user.FeedbackInfo;
import com.zbkj.common.model.user.UserInvoice;
import com.zbkj.common.page.CommonPage;
import com.zbkj.common.request.PageParamRequest;
import com.zbkj.common.request.user.AdminClientUserRequest;
import com.zbkj.common.request.user.AdminUserPwdRequest;
import com.zbkj.common.request.user.AdminUserQueryRequest;
import com.zbkj.common.response.CommonResult;
import com.zbkj.common.response.user.AdminClientUserResponse;
import com.zbkj.common.response.user.ClientUserInvoiceResponse;
import com.zbkj.common.response.user.FeedbackInfoResonse;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

/**
 * @Auther:
 * @Date: 2024/7/5 16:54
 * @Description:
 */
@RestController
@RequestMapping("api/admin/user")
@Api(tags = "服务端-客户管理服务")
public class AdminClientUserController {

    @Autowired
    private AdminClientUserService adminClientUserService;

    @ApiOperation(value = "客户用户列表")
    @PostMapping(value = "/list")
    public CommonResult<CommonPage<AdminClientUserResponse>> list(@RequestBody AdminUserQueryRequest queryRequest) {
        return CommonResult.success(CommonPage.restPage(adminClientUserService.list(queryRequest)));
    }

    //@PreAuthorize("hasAuthority('')")
    @ApiOperation(value = "新增客户用户保存")
    @PostMapping(value = "/save")
    public CommonResult save(@RequestBody @Validated({AdminClientUserRequest.CreateUserGroup.class}) AdminClientUserRequest userRequest) {
        adminClientUserService.userSave(userRequest);
        return CommonResult.success();
    }

    @ApiOperation(value = "获取客户信息")
    @GetMapping(value = "/getUser/{userId}")
    public CommonResult<AdminClientUserResponse> getUser(@PathVariable("userId") Long userId) {
        return CommonResult.success(adminClientUserService.getUser(userId));
    }

    @ApiOperation(value = "编辑客户用户保存")
    @PostMapping(value = "/update")
    public CommonResult update(@RequestBody @Validated({AdminClientUserRequest.UpdateUserGroup.class}) AdminClientUserRequest userRequest) {
        adminClientUserService.userUpdate(userRequest);
        return CommonResult.success();
    }

    @ApiOperation(value = "删除客户信息")
    @GetMapping(value = "/delUser/{userId}")
    public CommonResult delUser(@PathVariable("userId") Long userId) {
        adminClientUserService.delUser(userId);
        return CommonResult.success();
    }

    @ApiOperation(value = "更新客户状态")
    @GetMapping(value = "/statusUpdate/{userId}/{status}")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "status",value = "状态 0有效，1 封禁")
    })
    public CommonResult statusUpdate(@PathVariable("userId") Long userId, @PathVariable("status") Integer status) {
        adminClientUserService.statusUpdate(userId,status);
        return CommonResult.success();
    }

    @ApiOperation(value = "修改客户密码")
    @PostMapping(value = "/changePwd")
    public CommonResult changePwd(@RequestBody @Validated AdminUserPwdRequest pwdRequest) {
        adminClientUserService.changePwd(pwdRequest);
        return CommonResult.success();
    }
    @ApiOperation(value="获取客户发票信息")
    @GetMapping(value = "/getUserInvoice/{userId}")
    public CommonResult<UserInvoice> getUserInvoice(@PathVariable("userId") Long userId) {
        return CommonResult.success(adminClientUserService.getUserInvoice(userId));
    }

    @ApiOperation(value = "反馈意见列表")
    @PostMapping(value = "/getFeedbackList")
    public CommonResult<CommonPage<FeedbackInfoResonse>> getFeedbackList(@RequestBody PageParamRequest queryRequest) {
        return CommonResult.success(CommonPage.restPage(adminClientUserService.adminGetFeedbackList(queryRequest)));
    }
}
